package com.ss.android.newmedia.e;

import android.content.Context;
import com.bytedance.common.utility.collection.MaxSizeLinkedHashMap;
import com.ss.android.common.AbsApiThread;
import com.ss.android.common.load.AsyncLoader.LoaderProxy;
import com.ss.android.common.load.AsyncLoader;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.common.util.UrlBuilder;
import com.ss.android.newmedia.NewMediaConstants;
import com.ss.android.newmedia.f.k;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;

public final class m {
    final Context a;
    final MaxSizeLinkedHashMap b;
    final k c;
    AsyncLoader d;
    private static m e;
    private LoaderProxy f;

    private m(Context arg5) {
        this.a = arg5.getApplicationContext();
        this.b = new MaxSizeLinkedHashMap(16, 16);
        this.c = new k();
        this.f = new n(this);
        this.d = new AsyncLoader(16, 2, this.f);
    }

    public static m a(Context arg2) {
        m v0_1;
        Class v1 = m.class;
        synchronized (v1){
            if(m.e == null) {
                m.e = new m(arg2);
            }

            v0_1 = m.e;
        }
        return v0_1;
    }

    static k a(String arg4, String arg5) {
        k v0_2;
        JSONObject v2_1;
        k v1 = null;
        if(android.support.design.a.isTextEmpty(arg4)) {
            return v1;
        }

        if(android.support.design.a.isTextEmpty(arg5)) {
            return v1;
        }

        try {
            UrlBuilder v2 = new UrlBuilder(NewMediaConstants.clientAuthJsSdkConfigV1Url);
            v2.addParam("client_id", arg5);
            v2.addParam("partner_domain", arg4);
            String v0_1 = NetworkUtils.doGet(-1, v2.build());
            if(android.support.design.a.isTextEmpty(v0_1)) {
                return v1;
            }

            v2_1 = new JSONObject(v0_1);
            if(!AbsApiThread.isApiSuccess(v2_1)) {
                return v1;
            }

            v2_1 = v2_1.optJSONObject("data");
            if(v2_1 == null) {
                return v1;
            }

            v0_2 = new k();
        }
        catch(Exception v0) {
            return v1;
        }

        try {
            m.a(v2_1.optJSONArray("call"), v0_2.b);
            m.a(v2_1.optJSONArray("info"), v0_2.c);
            m.a(v2_1.optJSONArray("event"), v0_2.d);
        }
        catch(Exception v1_1) {
        }

        return v0_2;
    }

    private static void a(JSONArray arg4, List arg5) {
        if(arg4 != null && arg5 != null) {
            int v1 = arg4.length();
            int v0;
            for(v0 = 0; v0 < v1; ++v0) {
                String v2 = arg4.optString(v0);
                if(!android.support.design.a.isTextEmpty(v2)) {
                    arg5.add(v2);
                }
            }
        }
    }
}

